<?php

namespace App\Admin\Controllers;

use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class UsersController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '用户';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new User);

        $grid->column('id', __('Id'));
        $grid->column('nickname', __('昵称'));
        $grid->column('mobile', __('手机号'));
        $grid->column('status', __('状态'));
        $grid->column('level', __('会员级别'));
        $grid->column('sex', __('性别'));
        $grid->column('money', __('余额'));
        $grid->column('score', __('积分'));
        $grid->column('created_at', __('注册时间'));
        $grid->actions(function ($actions) {
            //$actions->disableDelete();
            //$actions->disableEdit();
            $actions->disableView();
        });
        $grid->disableCreateButton();
        $grid->disableExport();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('email', __('Email'));
        $show->field('email_verified_at', __('Email verified at'));
        $show->field('password', __('Password'));
        $show->field('remember_token', __('Remember token'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(User::findOrFail($id));
        $form->text('nickname', __('昵称'));
        $form->text('mobile', __('手机号'));
        $states = [
            'on'  => ['value' => 1, 'text' => '正常'],
            'off' => ['value' => 0, 'text' => '禁用'],
        ];
        $form->switch('status', '状态')->states($states);
        $form->checkbox('sex', __('性别'))->options([1 => '男',2 => '女']);
        $form->date('brith', __('生日'))->format('YYYY-MM-DD');
        $form->text('bref', __('签名'));
        $form->tools(function (Form\Tools $tools) {
               $tools->disableDelete();
               $tools->disableView();
               //$tools->disableList();
           });
        return $form;
    }
}
